<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="部门">
        <el-select v-model="formInline.departId">
          <el-option label="请选择" :value="0"></el-option>
          <el-option label="广州公司" :value="1"></el-option>
          <el-option label="北京公司" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="formInline.personName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getusermanage">查询</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="id" label="序号" width="100">
      </el-table-column>
      <el-table-column prop="personName" label="人员姓名" width="120">
      </el-table-column>
      <el-table-column prop="sortId" label="性别" width="100">
        <template slot-scope="scope">
          <div v-if="scope.row.sex == true">男</div>
          <div v-else>女</div>
        </template>
      </el-table-column>
      <el-table-column label="所属企业" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.firmId == 1">广州公司</div>
          <div v-else-if="scope.row.firmId == 2">北京公司</div>
        </template>
      </el-table-column>
      <el-table-column label="所属部门" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.departId == 1">开发部</div>
          <div v-else-if="scope.row.departId == 2">人事部</div>
        </template>
      </el-table-column>
      <el-table-column label="类型证件" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.idType == 1">身份证</div>
          <div v-else-if="scope.row.idType == 2">驾驶证</div>
        </template>
      </el-table-column>
      <el-table-column prop="idNum" label="证件号码" width="120">
      </el-table-column>
      <el-table-column prop="phone" label="手机号" width="120">
      </el-table-column>
      <el-table-column label="在线状态" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.state == true">在线</div>
          <div v-else>离线</div>
        </template>
      </el-table-column>
      <el-table-column label="最后登录" width="120">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button v-if="scope.row.state == true" type="text" @click="putusermanage(scope.row)">强退</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="count">
    </el-pagination>
  </div>
</template>
<script>
import { getusermanageapi, updatusermanagefalseapi } from "@/api/sysManage/UserManage"
import { getdepartmanageapi } from "@/api/sysManage/DepartManage"
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        departId: 0,
        personName: '',
      },
      count: 0,
      formData: {

      },
      selectDate: []
    }
  },
  methods: {
    getusermanage() {
      getusermanageapi(this.formInline).then(res => {
        this.tableData = res.data.data
        this.count = res.data.totalCount
      })
    },
    getdepartmanage() {
      getdepartmanageapi().then(res => {
        this.selectDate = res.data.data
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val
      this.getusermanage()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageIndex = val
      this.getusermanage()
    },
    resetForm() {
      this.formInline.roleName = ''
    },
    putusermanage(row) {
      this.formData = row
      if (confirm("确定要强退此用户吗？")) {
        updatusermanagefalseapi(this.formData).then(res => {
          if (res.data.message == "操作成功") {
            this.$message({
              message: '保存成功',
              type: 'success'
            });
            this.getusermanage()
            this.dialogputVisible = false
          }
          else {
            this.$message({
              message: '保存失败',
              type: 'error'
            });
          }
        })
      }
    }
  },
  created() {
    this.getusermanage()
    this.getdepartmanage()
  }
}
</script>
<style></style>